import wx


class MyFrame(wx.Frame):
    def __init__(self, parent, id):
        wx.Frame.__init__(self, parent, id, title="创建TextCtrl类", pos=(100, 100), size=(400, 300))
        # 创建面板

        panel = wx.Panel(self, -1)
        # 创建文本和输入框
        title = wx.StaticText(panel, label='请输入用户名和密码', pos=(140, 20))
        label_user = wx.StaticText(panel, label='用户名', pos=(50, 50))
        self.text_user = wx.TextCtrl(panel, pos=(100, 50), size=(235, 25), style=wx.TE_LEFT)
        label_pwd = wx.StaticText(panel, label='密码', pos=(50, 90))
        self.text_pwd = wx.TextCtrl(panel, pos=(100, 90), size=(235, 25), style=wx.TE_PASSWORD)
        # 创建“确认”和“取消”按钮
        bt_confirm = wx.Button(panel, label='确认', pos=(105, 130))
        bt_confirm.Bind(wx.EVT_BUTTON, self.OnClickSumbit)
        bt_cancel = wx.Button(panel, label='取消', pos=(195, 130))
        bt_cancel.Bind(wx.EVT_BUTTON, self.OnClickCancel)

    def OnClickSumbit(self, event):
        # 单击确定按钮，执行方法
        message = ""
        username = self.text_user.GetValue()
        pwd = self.text_pwd.GetValue()
        if username == "" or pwd == "":
            message = "用户名或密码不能为空"
        elif username == 'mr' and pwd == 'mrsoft':
            message = "登录成功"
        else:
            message = "用户名和密码不匹配"
        wx.MessageBox(message)

    def OnClickCancel(self, event):
        # 单击取消按钮，执行方法
        self.text_user.SetValue("")
        self.text_pwd.SetValue("")


if __name__ == '__main__':
    app = wx.App()
    frame = MyFrame(parent=None, id=-1)
    frame.Show()
    app.MainLoop()